package com.sgb.kjwl.view.ui.activity.transport.driver.price;

import android.app.Activity;
import android.content.Context;
import androidx.databinding.ViewDataBinding;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemPriceListBinding;
import com.sgb.kjwl.view.ui.adapter.AppRecyclerAdapter;

/**
 * Created by harisucici
 * Class description:
 */
public class PriceListAdapter extends AppRecyclerAdapter<PriceItemEntity, ItemPriceListBinding> {
    private BindingItemListen itemListen;
    private Context context;

    public PriceListAdapter(Activity context, BindingItemListen<PriceItemEntity, ItemPriceListBinding> itemListen) {
        super(context);
        this.context = context;
        this.itemListen = itemListen;
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_price_list;
    }

    @Override
    protected void onBindItem(final ItemPriceListBinding binding, final PriceItemEntity entity, final int position) {
        binding.getRoot().setOnClickListener((v) -> {
            itemListen.onItemClick(binding, entity, position);
        });
        binding.setEntity(entity);
        binding.executePendingBindings();
    }


    @FunctionalInterface
    public interface BindingItemListen<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);
    }

}